package com.flyou.ccnucenter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.Window;
import android.view.WindowManager;

import com.flyou.ccnucenter.ui.activity.MainActivity;
import com.flyou.ccnucenter.ui.activity.WelcomePager;
import com.flyou.ccnucenter.utils.NetUtils;
import com.flyou.ccnucenter.utils.SPUtils;

import cn.bmob.v3.Bmob;

public class Welcome extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 初始化 Bmob SDK
        // 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ClASS
        Bmob.initialize(this, "8ed6b1cf11e7cf79eb4e59634575baa7");
        // 设置满屏，不含系统状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // 设置满屏，不含软件标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
   //检测网络是否可用,检测是否是第一次进入app
        checkNetWorkAndIsFirstEnter();
    }


    private void checkNetWorkAndIsFirstEnter() {
        if (NetUtils.isConnected(Welcome.this)) {
            long startTime = SystemClock.elapsedRealtime();
            // 进行一些耗时操作 初始化数据 如数据库拷贝 联网升级 等


            long endTime = SystemClock.elapsedRealtime();
            if (endTime - startTime > 2000) {
                Constant.SPLASH_DISPLAY_LENGHT = 0;
            } else {
                Constant.SPLASH_DISPLAY_LENGHT = 2000 - (endTime - startTime);
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    Intent intent = new Intent();
                    if ((Boolean) SPUtils.get(Welcome.this, "isFirst", true)) {
                        SPUtils.put(Welcome.this, "isFirst", false);

                        intent.setClass(Welcome.this, WelcomePager.class);


                    } else {

                        intent.setClass(Welcome.this, MainActivity.class);


                    }
                    Welcome.this.startActivity(intent);
                    Welcome.this.finish();
                }
            }, Constant.SPLASH_DISPLAY_LENGHT);

        } else {
//            NetUtils.openSetting(Welcome.this);


        }

    }

}


